package com.doit.day04

/**
 * 增删改查
 */
object ArrayDemo {
  def main(args: Array[String]): Unit = {
    //创建数组的第二种方式(不推荐使用)
    val ints: Array[Int] = new Array[Int](5)
/*    for (elem <- ints) {
      println(elem)
    }*/
//    println(ints)//[I@66d33a  没有重写toString方法

    /*println(ints.length)
    //更新
    ints.update(0,100)

    //获取索引对应的元素
    println(ints.apply(0))
    println(ints.apply(1))
    println(ints(2))
    println(ints(3))

    println(ints.mkString("_"))//将每个元素都拿过来做一个拼接，参数指的是拼接的连接符 _

/*    val str: String = ints.+("hello")
    println(str)*/


    println("========帅气的============")
    //给原来的数组添加一个元素，但是会返回一个新的数组给我们
    val ints1: Array[Int] = ints.:+(10)
    println(ints1.mkString(","))

    val ints2: Array[Int] = ints.+:(20)
    println(ints2.mkString(","))

    val ints3: Array[Int] = ints.++(ints1)
    val ints4: Array[Int] = ints.++:(ints1)
    println(ints3.mkString(","))
    println(ints4.mkString(","))*/


    val arr: Array[Int] = Array(1, 2, 3, 4, 5)
    //删除两个还是删除索引是2的元素
    val ints1: Array[Int] = arr.drop(2)
    println(ints1.mkString(","))//3,4,5

    /**
     * 从左往右去用函数依次判断，如果遇到false 就停止
     */
  /*  val ints2: Array[Int] = arr.dropWhile(e => e % 2 == 0)
    println(ints2.mkString(","))//1,2,3,4,5

    val ints3: Array[Int] = arr.dropWhile(e => e % 2 == 1)
    println(ints3.mkString(","))//2,3,4,5

    val arr1: Array[Int] = Array(1, 1, 3, 4, 5)
    val ints4: Array[Int] = arr1.dropWhile(e => e % 2 == 1)
    println(ints4.mkString(","))//4,5*/











  }

}
